<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div>
        <button>点击</button>
    </div>
    <form action="">
        <input type="text" name="user">
        <input type="reset" id="submit">
        
    </form>
    <script>
        /*
            IE可以使用 window.event
            IE8及以下版本只能使用window.event 
            IE9及以上版本支持传参的方式

            谷歌两种方式都支持

            火狐只支持传参的方式获取event对象

            在函数内获取event对象
                var event = event || window.event;

            event.stopPropagation(); 主流浏览器
            event.cancelBubble = true;  ie

            解决阻止冒泡的兼容性问题
            function stopPropagation(event){
                if(event.stopPropagation){
                    event.stopPropagation();
                }else{
                    event.cancelBubble = true;
                }
            }
                

            解决阻止浏览器默认行为的兼容
            event.preventDefault() //Firefox/Chrome/Opera/Safari
            event.returnValue = false  //ie

            function stopDefault(event){
                if(event.preventDefault){
                    event.preventDefault();
                }else{
                    event.returnValue = false;
                }
            }

        */
        var box = document.getElementsByTagName("div")[0];
        var btn = document.getElementsByTagName("button")[0];
        function stopPropagation(event){
            if(event.stopPropagation){
                event.stopPropagation();
            }else{
                event.cancelBubble = true;
            }
        }


        function showBox () {
            alert("点击了box")
        }
        // function showBtn(event){
        function showBtn(){
            // var event = event || window.event;
            alert("点击了BTN");
            stopPropagation(event);
        }

        box.onclick = showBox;
        // btn.onclick = function (event){
        btn.onclick = function (){
            showBtn(event);
        }


        /******************兼容阻止默认事件******************/
        function stopDefault(event){
         if(event.preventDefault){
             event.preventDefault();//该方法支持谷歌火狐 不支持IE
         }else{
             event.returnValue = false;//该方法火狐不支持
         }
        }
        function showSub(event){
            var event = event||window.event;//用于兼容IE
            alert(1);
            // stopDefault(event);
            // event.returnValue = false;
            event.preventDefault();
        }
        var submit = document.getElementById('submit');
        submit.onclick = function(event){
            showSub(event);
        }


        /***********************************/
        function a(){
            alert(window.event);
        }
        function b(event){
            // alert(event);
            var event = event || window.event;
        }
        // document.onclick = a;
        /*document.onclick = function(event){
            b(event);
        }*/
    </script>
</body>
</html>